package com.wwcom.darteagle.model;

import java.util.List;

import android.content.Context;

import com.wwcom.darteagle.data.DartEagleDatabase;

public class GlobalAppData {
	private static GlobalAppData instance = null;
	public Match match;
	public MatchInfo matchInfo;
	public List<DartStats> dartStats;
	private Match loadedMatch;
	
	private GlobalAppData() {
		loadedMatch= null;
	}
	
    public static GlobalAppData getSingletonInstance()
    {
      if (instance == null)
          // it's ok, we can call this constructor
    	  instance = new GlobalAppData();
      return instance;
    }	
    
    public Object clone() throws CloneNotSupportedException
    {
    	throw new CloneNotSupportedException(); 
    }	
    
    public Match getMatch(long matchId, Context context) {
    	if (matchId == -1)
    		return match;
    	
    	if (loadedMatch != null && loadedMatch.getId() == matchId) {
    		return loadedMatch;
    	}
		DartEagleDatabase db= new DartEagleDatabase(context);             	    	
		loadedMatch= db.getMatch(matchId);
		db.close();
    	return loadedMatch;
    }
}
